package ua.kpi.oblamskyiv;

import ua.kpi.oblamskyiv.io.ClientIO;

/**
 * Managing login and logout operations
 */
public class LoginManager {
    private static final User ANONYMOUS = new User("Anonymous");
    private static LoginManager instance = null;
    private ClientIO clientIO;
    private boolean logged;
    private User loggedUser;

    private LoginManager() {
        clientIO = new ClientIO();

        loggedUser = ANONYMOUS;
        logged = false;
    }

    public static LoginManager getInst() {
        if (instance == null) {
            instance = new LoginManager();
        }
        return instance;
    }

    public void login() {
        loggedUser = new User(clientIO.getUserName());
        logged = true;
    }

    public void logout() {
        loggedUser = ANONYMOUS;
        logged = false;
    }

    public boolean isLogged() {
        return logged;
    }

    public User getUser() {
        return loggedUser;
    }
}
